import 'dart:async';

import 'package:flutter/material.dart';
import 'package:my_flutter_github/page/HomePage.dart';
import 'package:my_flutter_github/page/LoginPage.dart';
import 'package:my_flutter_github/page/WelcomePage.dart';

import 'package:redux/redux.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:my_flutter_github/redux/MyState.dart';
import 'package:my_flutter_github/MyStyle.dart';

//这里不能随便使用model/User.dart，最好全部使用全路径的，否则编译会报错
//import 'model/User.dart';
import 'package:my_flutter_github/model/User.dart';

void main() => runApp(new FlutterReduxApp());

class FlutterReduxApp extends StatelessWidget {
  /// 创建Store，引用 GSYState 中的 appReducer 创建 Reducer
  /// initialState 初始化 State
  final store = new Store<MyState>(
    appReducer,
    initialState: new MyState(
      userInfo: User.empty(),
      eventList: List(),
      trendList: List(),
      themeData: new ThemeData(
          primarySwatch: MyColors.primarySwatch,
          platform: TargetPlatform.iOS
      ),
    ),
  );

  final Map<String, WidgetBuilder> _routes = <String, WidgetBuilder>{
   WelcomePage.sName: (context) {
      return new WelcomePage();
    },
    HomePage.sName:(context) {
        return new HomePage();
    },
    LoginPage.sName: (context) {
      return new LoginPage();
    }
  };

  FlutterReduxApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return new StoreProvider(
      store: store,
      child: new StoreBuilder<MyState>(
        builder: (context, store) {
          return new MaterialApp(
            title: "Redux App",
            theme: store.state.themeData,
            routes: _routes,
          );
        },
      ),
    );
  }
}
